using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FlatRedBall;
using FlatRedBall.Graphics;
using FlatRedBall.Input;


namespace Like_a_bomberman
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Jugador : GameComponentCollision
    {
        Text texto;
        float colisiones = 0;
              

        public Jugador(Game game)
            : base(game, 1)
        {


            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

           


            sprite = SpriteManager.AddSprite("Bomberman.png");
            sprite.X = -10;
            sprite.Y = 10;


            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            sprite.XVelocity = 0;
            sprite.YVelocity = 0;

        

            if (InputManager.Keyboard.KeyDown(Keys.Left))
            {
                
                 sprite.XVelocity = -7;
                   
                
            }
            else if (InputManager.Keyboard.KeyDown(Keys.Right))
            {
               
              sprite.XVelocity = 7;
                    
             }
            else if (InputManager.Keyboard.KeyDown(Keys.Up))
            {
               
                    sprite.YVelocity = 7;
       
                
            }

            else if (InputManager.Keyboard.KeyDown(Keys.Down))
            {
                               
                    sprite.YVelocity = -7;
                  
            }

            else if (InputManager.Keyboard.KeyPushed(Keys.Space))
            {
                Bomba bomba = new Bomba(this.Game, sprite.X, sprite.Y);

                this.Game.Components.Add(bomba);

            }

            if (InputManager.Keyboard.KeyPushed(Keys.M))
            {
                Bomba2 bomba = new Bomba2(this.Game, sprite.X, sprite.Y, -11, 8, -12);
                this.Game.Components.Add(bomba);

                Bomba2 bomba2 = new Bomba2(this.Game, sprite.X, sprite.Y, 11, -8, -12);
                this.Game.Components.Add(bomba2);

                Bomba2 bomba3 = new Bomba2(this.Game, sprite.X, sprite.Y, -9, 9, -11);
                this.Game.Components.Add(bomba3);

                Bomba2 bomba4 = new Bomba2(this.Game, sprite.X, sprite.Y, 9, -9, -11);
                this.Game.Components.Add(bomba4);

            }

            TextManager.RemoveText(texto);
            texto = TextManager.AddText("Colisiones =" + colisiones);
            texto.X = 2;
            texto.Y = 10;
            texto.Scale = 2;
            texto.Spacing = 1.8f;

            base.Update(gameTime);
        }

        public override void Collision(GameComponentCollision component)
        {
            if (component is Bloque)
            {
                colisiones = colisiones + 1;

                sprite.CollideAgainstMove(component.sprite, 1, 10000);

                component.sprite.XVelocity = 0;
                component.sprite.YVelocity = 0;
            }

            if (component is Bloque_destructible)
            {
                colisiones = colisiones + 1;

                sprite.CollideAgainstMove(component.sprite, 1, 10000);

                component.sprite.XVelocity = 0;
                component.sprite.YVelocity = 0;

            }
       
        }
    }


}
